<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']);
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_scrm_store_group',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['status']=array('0'=>'不显示','1'=>'显示');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'门店组管理'),
			array('op'=>'edit','title'=>'添加门店组'),
		),
		'list'=>array('data'=>'list','tip'=>'比如：深圳组','list'=>array(
			array('name'=>'title','title'=>'门店组','type'=>'string'),
			array('name'=>'image','title'=>'图片','type'=>'image'),
			array('name'=>'status','title'=>'是否显示','type'=>'radio','options'=>'status'),	
				
		)),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_scrm_store_group',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	$return['status']=array('0'=>'不显示','1'=>'显示');
	$return['isrecommand']=array('0'=>'不推荐','1'=>'推荐');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'门店组设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'门店组管理'),
			array('op'=>'edit','title'=>'添加门店组')
		),
		'edit'=>array(			
			array('name'=>'title','title'=>'设置门店组','type'=>'string','help'=>'比如：深圳组'),
			array('name'=>'status','title'=>'是否显示','type'=>'radio','options'=>'status'),	
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title'] ){
		exi('请填写标题','error');
	}
	$data=array_fields(array('title','paixu','status'),$postdata);
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_scrm_store_group',$data,array('id'=>$id));
				exi('设置成功！','','/store.group/');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				$data['merchid']=$_SESSION['onemerchid'];
				 $data['createtime']=time();
				pdo_insert('jy_scrm_store_group',$data);
				exi('添加成功！','','/store.group/');
			}
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_scrm_store_group',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_scrm_store_group',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>